<?
##########################################################################
#		DOCUMENTATION
##########################################################################
# Class that extends the rootclass. This module will provide common methods
# to all the "listing classes" i.e. all classes that lists some query-results
#
# © LiberLab group, 2011
##########################################################################

require_once("root.php");

class BaseList extends Root{
	# use parent construct directly
	
	public function prevNext($skipNum){
		# build in auto the previous and next buttons
			
		$this->limits = array(5, 10, 20); 
		$indMaxLimit = count($this->limits);
		$query = $_SERVER["REQUEST_URI"];
		
		$query = str_replace("&", "&amp;", $query); # keep the result xhtml strict valid

		$link = preg_replace("/&amp;limit=[^&]*/", "", $query);
		$this->tagHash["limitLinkINDEX§§§§limitINDEX"] = $indMaxLimit;
		$cont = 0;
		$newLink;
		foreach($this->limits as $singleLimit){
			$newLink = $link . "&amp;limit=$singleLimit"; 
			$newLink = str_replace("?&amp;", "?", $newLink);
			$this->tagHash["limitLink$cont"] = $newLink;
			if (count($this->limits) == ($cont+1)){
				$this->tagHash["limit$cont"] = $singleLimit . "."; 
			}else{
				$this->tagHash["limit$cont"] = $singleLimit . ","; 
			}
			$cont++;
		}
		$link = preg_replace("/&amp;startid=[^&]*/", "", $query);	
		# previous
		if ($this->startId == 0){
			$temp = $this->messages["previousWithoutLink"];
		}else{
			$temp = $this->messages["previousLink"];
		}
		$newStartId = $this->startId-$this->limit;
		if ($newStartId < 0){ $newStartId = 0; }
		$newLink = $link . "&amp;startid=$newStartId";

		$this->tagHash["previous"] = str_replace("__limit__", $this->limit, str_replace("__previousLink__", $newLink, $temp));
		# next	
		# numbooks should be one more than limit because we use LIMIT 0,5 (and not 1,5 or 0,4 as should be)
		# to see if there is a book that "follows" or not
		if ($this->limit > $skipNum){
			$temp = $this->messages["nextWithoutLink"];
		}else{
			$temp = $this->messages["nextLink"];
		}
		$newStartId = $this->startId+$this->limit;
		
		$newLink = $link . "&amp;startid=$newStartId";
		$newLink = str_replace("?&", "?", $newLink);
		
		$this->tagHash["next"] = str_replace("__limit__", $this->limit, str_replace("__nextLink__", $newLink, $temp));
	}

	public function __destruct() {
		parent::__destruct();
	}
};

?>
